//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#define WATCH_DOG 0
#define WDOG_MSG 1
#define WATCHDOG_MSG(x, y) if(x) y
#define MAX_WD_TSK_NODE 32
/* 40000 (10ms) * 200 = 2s */
#define WTD_FEED_TIME_CLK   8000000
#define WTD_FEED_TIME_SEC   2

typedef enum {
    TSK_PING  = 0, /*Task start ping watchdog, watchdog waiting for feed*/
    TSK_FEED  = 1, /*Task has feed the watchdog, task still alive*/
    TSK_WATCH = 2, /*Task watchdog is awake, it's waiting for ping*/
    TSK_SLEEP = 3, /*This Task's Watchdog is Sleep*/
    TSK_FIRE  = 4, /*Watchdog's feed time is expired*/
} WD_TASK_STATE;


typedef struct {
    int    TskID; /*Task ID been Monitor*/
    int    PingID; /*Ping ID in Task*/
    UInt32  PingStamp; /* Ping start time stamp */
    WD_TASK_STATE    TskState;
    void   **TasReinitHanle; /* Pointer to task restart function */
    char*   TskString; /*Task Descriptor .. if Need*/
}WD_Tsk_Node;

/* Hardware watchdog timer */
EXTERN_C void watchdog_xllp_fire(void);

/* API Used for Multi Task */
EXTERN_C int watchdog_init(void);
EXTERN_C int watchdog_exit(void);
EXTERN_C int watchdog_reset(void);
EXTERN_C int watchdog_sleep(int TskID);
EXTERN_C int watchdog_open(char *TaskString);
EXTERN_C void watchdog_feed(int TskID, int PingID);
EXTERN_C void watchdog_ping(int TskID);
EXTERN_C void watchdog_sn_ping();
EXTERN_C void watchdog_sn_feed();

/* Macro*/
#if (WATCH_DOG)
#define WATCHDOG_INIT()      watchdog_init()
#define WATCHDOG_EXIT()      watchdog_exit()
#define WATCHDOG_RESET()     watchdog_reset()
#define WATCHDOG_SLEEP(x)    watchdog_sleep(x)
#define WATCHDOG_OPEN(x)     watchdog_open(x)
#define WATCHDOG_FEED(x, y)  watchdog_feed(x, y)
#define WATCHDOG_PING(x)     watchdog_ping(x)
#define WATCHDOG_SN_PING()          watchdog_sn_ping()
#define WATCHDOG_SN_FEED()          watchdog_sn_feed()

#else
#define WATCHDOG_INIT()
#define WATCHDOG_EXIT()
#define WATCHDOG_RESET()
#define WATCHDOG_SLEEP(x)
#define WATCHDOG_OPEN(x)
#define WATCHDOG_FEED(x)
#define WATCHDOG_PING(x, y)
#define WATCHDOG_SN_PING()
#define WATCHDOG_SN_FEED()

#endif
